import type { DnsAddressPoolListItem } from '@/apis/model/dns'
import { getDnsAuthorityGtmAddressPoolsApi } from '@/apis/modules/dns'

export default function useAddressPoolData() {
  const type = inject('addressPoolType') as ComputedRef<1 | 2>
  const queryParams = ref({
    limit: 0,
    offset: 0,
    order: 'desc',
    sort: 'created_at',
    type,
  })
  const data = ref<DnsAddressPoolListItem[]>([])
  const { loading, run } = useListRequest(getDnsAuthorityGtmAddressPoolsApi, {
    params: queryParams,
    afterFn: (list) => {
      data.value = list.map(item => ({
        ...item,
        value: item.id || '-',
      }))
    },
  })

  onMounted(() => {
    run()
  })
  return { loading, data, run }
}
